package com.situ.controller.cst_lost;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.situ.entity.bas_dict.BasDict;
import com.situ.entity.customer.CstCustomer;
import com.situ.entity.might.SysMight;
import com.situ.service.bas_dict.BasDictService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.situ.service.cst_lost.CstLostService;
import com.situ.entity.cst_lost.CstLost;
import com.situ.util.*;

import java.util.List;

/**
 * CstLost的路由接口服务
 * 
 * @author胡文
 *
 */
//
@RestController
public class CstLostController {

	/** CstLostService服务 */
	@Autowired
	private CstLostService cstLostService;
    @Autowired
    private BasDictService basDictService;

    /**
	 * 查询所有CstLost数据的方法
	 * @param value
	 * @return
	 */
	@RequestMapping(value = "/CstLost/query", produces = {"application/json;charset=UTF-8"})
	public ResponseData query(CstLost value) {

		return ResponseData.ok().putDataValue("list",cstLostService.find(value));
	}
	
	/**
	 * 通过id查询CstLost数据的方法
	 * 
	 * @return
	 */
	@RequestMapping(value = "/CstLost/queryById/{id}", produces = {"application/json;charset=UTF-8"})
	public ResponseData queryById(@PathVariable(name="id") Long id) {
		 return ResponseData.ok().putDataValue("obj",cstLostService.findOne(id));
	}
	
	/**
	 * 插入CstLost属性不为空的数据方法
	 * 
	 * @return
	 */
	@RequestMapping(value = "/CstLost/save")
	public ResponseData save(CstLost value) {
		return ResponseData.ok().putDataValue("obj", cstLostService.saveNotNull(value));
	}
	
	/**
	 * 更新CstLost属性不为空的数据方法
	 * 
	 * @return
	 */
	@RequestMapping(value = "/CstLost/update", produces = {"application/json;charset=UTF-8"})
	public ResponseData update(CstLost value) {
		return ResponseData.ok().putDataValue("obj",cstLostService.updateNotNullById(value));
	}

	/**
	 * 通过id删除CstLost数据方法
	 * 
	 * @return
	 */
	@RequestMapping(value = "/CstLost/delById/{id}", produces = {"application/json;charset=UTF-8"})
	public ResponseData delById(@PathVariable(name="id") Long id) {
		return ResponseData.ok().putDataValue("obj",cstLostService.deleteById(id));
	}


    //带分页的查询全部
//@ApiOperation("带分页的查询全部")

    @RequestMapping(value = "/CstLost/queryPage", produces = {"application/json;charset=UTF-8"})
    public ResponseData queryPage(CstLost value,
                                  @RequestParam(defaultValue = "1",required = false) int pageNum ,
                                  @RequestParam(defaultValue = "5",required = false) int pageSize) {

        PageHelper.startPage(pageNum, pageSize);
        List<CstLost> list = cstLostService.queryBylike(value);
        PageInfo pageInfo = new PageInfo<CstLost>(list, 5);

        return ResponseData.ok()
                // .putDataValue("list", list)
                .putDataValue("pageInfo", pageInfo);
        }


        @RequestMapping("/CstLost/queryliushizt")//查询客户流失所有的状态
        public List<BasDict> queryzt(BasDict value){
            List<BasDict> list = basDictService.queryliushi(value);
            return list;
        }


    @RequestMapping("/CstLost/updateyuanying")//确认流失的原因
    public String updateliu(CstLost value){
        cstLostService.updateliu(value);
        String mess="保存成功";
        return  mess;
    }

    @RequestMapping("/CstLost/updatecs")//确认流失的原因
    public String updatecs(CstLost value){
        cstLostService.updatecs(value);
        String mess="保存成功";
        return  mess;
    }
}
